﻿using System;
using System.Collections.Generic;
using System.Text;
using FunctionalCLR.Core;

namespace FunctionalCLR.Core.Function.List {

    /// <summary>
    /// a = [1,2,3];
    /// b = [4,5];
    /// c = join(a, b);
    /// echo(c);
    /// </summary>
    public class ListConcatNode : FuncNode {

        public ListConcatNode()
            : base() {
            this.Value = "join";
        }

        public override FuncNode GetReversedFunction(int index) {
            throw new NotImplementedException();
        }

        public override object Evaluate() {
            ListNode result = new ListNode();

            foreach (Node child in Children) {
                ListNode c = (ListNode)child;
                c.Evaluate();

                foreach (Node cx in c.Children) {
                    result.Children.Add(cx);
                }
            }

            return result;
        }
    }
}
